package com.woniu.controller;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.woniu.entity.FinalTrialClientInfoVO;
import com.woniu.entity.SecondTrial;
import com.woniu.service.SecondTrialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 复审列表
 * @author: sunkun
 * @date: 2022/9/24 10:45
 * @version 1.0
 */
@Api(value = "复审列表", tags = {"复审"})
@RestController
@RequestMapping("/secondTrial")
public class SecondTrialController extends BaseController {
    @Resource
    SecondTrialService secondTrialService;

    @ApiOperation(value = "查询所有复审订单", response= SecondTrial.class,  httpMethod="GET", tags = {"复审"})
    @ApiImplicitParam(name = "secondTrial",value = "复审实体",required = true)
    @GetMapping("/secondTrialList")
    public TableDataInfo findSecondTrial(SecondTrial secondTrial){
        startPage();
        List<SecondTrial> allSecondTrial =  secondTrialService.findSecondTrial(secondTrial);
        return getDataTable(allSecondTrial);
    }

    @ApiOperation(value = "通过订单id查询审核转态", response= Integer.class, httpMethod="GET", tags = {"复审"})
    @GetMapping("/auditStatus/{loanId}")
    public AjaxResult findAuditStatus(@ApiParam(value = "订单的id") @PathVariable Integer loanId){
        SecondTrial secondTrial = secondTrialService.findAuditStatus(loanId);
        System.out.println(secondTrial);
        return new AjaxResult(HttpStatus.SUCCESS,"查询成功",secondTrial);
    }

    @ApiOperation(value = "复审意见", response= SecondTrial.class, produces="application/json", httpMethod="PUT", tags = {"复审"})
    @PutMapping ("/updateRiskControl")
    public AjaxResult updateRiskControl(@RequestBody SecondTrial secondTrial){
        boolean b = secondTrialService.secondTrialAdvice(secondTrial);
//        System.out.println(b);
        if(secondTrialService.secondTrialAdvice(secondTrial)){
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

}
